package o;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class anh {
    private static final Comparator<e> ˎ = anl.ˎ;
    private static final Comparator<e> ॱ = anj.ˊ;
    private int ʻ;
    private int ʼ;
    private int ʽ;
    private final int ˊ;
    private final ArrayList<e> ˋ = new ArrayList();
    private final e[] ˏ = new e[5];
    private int ᐝ = -1;

    static class e {
        public int ˋ;
        public int ˏ;
        public float ॱ;

        private e() {
        }
    }

    public anh(int i) {
        this.ˊ = i;
    }

    public void ˎ(int i, float f) {
        int i2;
        e eVar;
        ˎ();
        if (this.ʼ > 0) {
            e[] eVarArr = this.ˏ;
            i2 = this.ʼ - 1;
            this.ʼ = i2;
            eVar = eVarArr[i2];
        } else {
            eVar = new e();
        }
        i2 = this.ʽ;
        this.ʽ = i2 + 1;
        eVar.ˋ = i2;
        eVar.ˏ = i;
        eVar.ॱ = f;
        this.ˋ.add(eVar);
        this.ʻ += i;
        while (this.ʻ > this.ˊ) {
            i2 = this.ʻ - this.ˊ;
            eVar = (e) this.ˋ.get(0);
            if (eVar.ˏ <= i2) {
                this.ʻ -= eVar.ˏ;
                this.ˋ.remove(0);
                if (this.ʼ < 5) {
                    e[] eVarArr2 = this.ˏ;
                    int i3 = this.ʼ;
                    this.ʼ = i3 + 1;
                    eVarArr2[i3] = eVar;
                }
            } else {
                eVar.ˏ -= i2;
                this.ʻ -= i2;
            }
        }
    }

    public float ॱ(float f) {
        ॱ();
        float f2 = f * ((float) this.ʻ);
        int i = 0;
        for (int i2 = 0; i2 < this.ˋ.size(); i2++) {
            e eVar = (e) this.ˋ.get(i2);
            i += eVar.ˏ;
            if (((float) i) >= f2) {
                return eVar.ॱ;
            }
        }
        return this.ˋ.isEmpty() ? Float.NaN : ((e) this.ˋ.get(this.ˋ.size() - 1)).ॱ;
    }

    private void ˎ() {
        if (this.ᐝ != 1) {
            Collections.sort(this.ˋ, ॱ);
            this.ᐝ = 1;
        }
    }

    private void ॱ() {
        if (this.ᐝ != 0) {
            Collections.sort(this.ˋ, ˎ);
            this.ᐝ = 0;
        }
    }
}
